home *** CD-ROM | disk | FTP | other *** search
- /*
- * utility to convert image types.
- *
- * WARNING WARNING WARNING WARNING WARNING WARNING
- *
- * this program does NOT have a Mac-style user interface
- *
- * WARNING WARNING WARNING WARNING WARNING WARNING
- */
- #include <stdio.h>
- #include "rawfmt.h"
-
- #define MAGIC_C ((unsigned char)'┼')
-
- #define SFPGET_ID 400
- #define D_Folder 11 /* folder button */
-
- int GetSunRast(), TIFFToRaw();
-
- int (*getType[])() = {
- GetSunRast,
- TIFFToRaw,
- NULL,
- };
-
- pascal int dirDlgHook(int item, DialogPtr d) {
-
- if (item == D_Folder) /* 'use folder' */
- item = 1; /* getOpen */
- return item;
- }
-
- main(argc, argv) char **argv; {
- SFReply sf;
- int volNum;
- long dirID, proc;
- again:
- printf(":\n"); /* open 'console' window */
-
- SFPGetFile(0x00600060, "", 0L, 1, "", dirDlgHook, &sf, SFPGET_ID, 0L);
- if (!sf.good)
- return;
-
- if (sf.fName[0] != 0) { /* this _cannot_ happen since no typeList is given */
- fprintf(stderr,"Choose a directory\n");
- goto again;
- }
- HGetVol(NULL, &volNum, &dirID);
- dirID = sf.fType; /* replace with that chosen by user */
-
- scanDir(volNum, dirID);
-
- printf("%20c",' '); /* blank last line */
- }
-
- /* scan globals */
- HFileInfo h;
- Str255 fName;
-
- scanDir(int volNum, long dirID)
- {
- int index=1;
-
- h.ioNamePtr = fName;
- h.ioVRefNum = volNum;
-
- for (;;) {
- h.ioFDirIndex = index++;
- h.ioDirID = dirID;
- if (PBGetCatInfo(&h, FALSE) != noErr) {
- if (h.ioResult != fnfErr) { /* end of folder */
- PtoCstr((char *)fName);
- fprintf(stderr,"%s: PBGetCatInfo = %d\n",fName,h.ioResult);
- }
- return;
- }
- /* recursively descend directory hierarchy */
- if ((h.ioFlAttrib & ioDirMask))
- scanDir(volNum, h.ioDirID);
- else {
- h.ioDirID = dirID; /* fudge back parent's dirID */
- Convert(&h);
- }
- }
- }
-
- Convert(HFileInfo *hp)
- {
- raw_t image;
- int i, done=0;
-
- PtoCstr((char *)hp->ioNamePtr);
- printf("%-20.20s\r",hp->ioNamePtr);
- CtoPstr((char *)hp->ioNamePtr);
-
- /* skip already processed files and files with no data fork */
- if ((unsigned char)hp->ioNamePtr[hp->ioNamePtr[0]] == MAGIC_C ||
- h.ioFlLgLen == 0L)
- return;
-
- /*
- * call each getType routine to see if it recognizes the file
- * (more efficient approach would be to read the first chunk of the file once
- * and have 'validate' entry points for each type).
- */
- image.data = NULL;
- for (i=0; !done && getType[i]; i++) {
- if ((*getType[i])(hp, &image) == TRUE) {
- /* change name to 'NAME┼' */
- hp->ioNamePtr[0]++;
- hp->ioNamePtr[hp->ioNamePtr[0]] = MAGIC_C;
- PtoCstr((char *)hp->ioNamePtr);
- printf(" Making: %s\n",hp->ioNamePtr);
- CtoPstr((char *)hp->ioNamePtr);
-
- RawToSCMI(hp, &image);
- done = 1;
- }
- if (image.data) {
- DisposPtr(image.data);
- image.data = NULL;
- }
- }
- }